/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 jfinal app. jfapp Group.
 */


define(['adminapp', 'core/datatable', 'bootstrap-datepicker', 'bootstrap-datepicker-zh'], function ($app) {
    $app.navactive('member');

    $('.date-picker').datepicker({
        language      : 'zh-CN',
        rtl: App.isRTL(),
        autoclose: true
    });

    var $listtable = $app.listtable({
        'sAjaxSource' : g.ctx + "admin/stat/integral/list",
        'fnServerParams': function( aoData){
            var sd = $('#search_form').serializeJSON();
            $.each(sd, function(name, val){
                aoData.push({"name": name, "value": val});
            });
        },
        'aoColumns'   : [
            $app.checkall,
            $app.autono,
            {'mDataProp': 'record_time' },
            {'mDataProp':  null },
            {'mDataProp': null },
            {'mDataProp': null },
            {'mDataProp': 'resume', bSortable: false}
        ],
        'aoColumnDefs': [
            {
                'aTargets' : [3],
                'mData'    : null,
                "bSortable": false,
                'mRender'  : function (data, type, full) {
                    return full['subtraction'] == 1 ? '<span class="badge badge-info">' + full['integral'] + '</span>' : '';
                }
            },
            {
                'aTargets' : [4],
                'mData'    : null,
                "bSortable": false,
                'mRender'  : function (data, type, full) {
                    return full['subtraction'] == 0 ? '<span class="badge badge-warning">' + full['integral'] + '</span>' : '';
                }
            },
            {
                'aTargets' : [5],
                'mData'    : null,
                "bSortable": false,
                'mRender'  : function (data, type, full) {
                    return full['subtraction'] == 1 ? full['old_integral'] + full['integral'] : full['old_integral'] - full['integral'];
                }
            }
        ]
    }, 'data-list');

    $('#search_btn').on('click', function (e) {
        e.preventDefault();
        $listtable.fnReloadAjax();
    });
});

